package apIExercise.collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection c=new ArrayList();
        c.add("abc");
        c.add("one");
        c.add("two");
        System.out.println(c);//[abc, one, two]
        //集合的元素的个数
        System.out.println(c.size());//3
        //判断是否是空集合
        System.out.println(c.isEmpty());//false
        String s="阿芬";
        String s1="abc";
        System.out.println(c.contains(s));//false
        System.out.println(c.contains(s1));//true

        c.clear();//清空集合
        System.out.println(c.size());//0
        System.out.println(c);//[]

        //判断是否是空集合
        System.out.println(c.isEmpty());//true

        Collection c1=new ArrayList();
        c1.add(new Point(1,2));
        c1.add(new Point(3,4));
        c1.add(new Point(5,6));
        c1.add(new Point(7,8));
        System.out.println(c1);//[(1,2), (3,4), (5,6), (7,8)]
        //创建一个对象
        Point p=new Point(1,2);
        Point p1=new Point(3,4);
        System.out.println(p);//(1,2)
        System.out.println(p1);//(3,4)
        boolean contains=c1.contains(p);//true
        System.out.println(contains);//ture 比较的是地址不是内容需要重写Point

        //删除集合的元素
        c1.remove(p1);
        c1.remove(p);
        System.out.println(c1);//[(5,6), (7,8)]

        Collection cc=new ArrayList();
        Point pp=new Point(1,2);
        cc.add(pp);//往集合里添加pp
        System.out.println("cc:"+cc);//cc:[(1,2)]
        System.out.println("pp:"+pp);//pp:(1,2)

        //修改引用的数值,集合也跟一起改变，因为共用一个地址
        pp.setX(100);
        System.out.println("cc:"+cc);//cc:[(100,2)]
        System.out.println("pp:"+pp);//pp:(100,2)
        pp.setY(500);
        System.out.println("cc:"+cc);//cc:[(100,500)]
        System.out.println("pp:"+pp);//pp:(100,500)






    }
}
